package com.vmtest;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
//import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;
//import android.widget.ViewFlipper;

import com.vmtest.R;

public class frmpostvisitas extends Activity {
	
	 @Override
	    public void onCreate(Bundle savedInstanceState) {
	    	super.onCreate(savedInstanceState);
			setContentView(R.layout.frmpostvisitas);
			
			//*** Carga Spinner Filtro - Medicos ***//		
			Spinner prueba = (Spinner) findViewById(R.id.spinner1);
			//Creamos el adaptador
			ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.filtroficheroME,android.R.layout.simple_spinner_item);		
			//Añadimos el layout para el menú
			adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
			//Le indicamos al spinner el adaptador a usar
			prueba.setAdapter(adapter);
			
			//*** Carga Spinner Filtro - CS ***//		
			Spinner prueba1 = (Spinner) findViewById(R.id.spinner2);
			ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(this,R.array.filtroficheroCS,android.R.layout.simple_spinner_item);
			adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
			prueba1.setAdapter(adapter1);		
			
			//*** Carga Spinner Filtro - Farmacias ***//
			Spinner prueba11 = (Spinner) findViewById(R.id.spinner3);
			ArrayAdapter<CharSequence> adapter11 = ArrayAdapter.createFromResource(this,R.array.filtroficheroFA,android.R.layout.simple_spinner_item);
			adapter11.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
			prueba11.setAdapter(adapter11);
			
			Resources res = getResources();
	        
	        TabHost tabs=(TabHost)findViewById(android.R.id.tabhost);
	        tabs.setup();
	        
	        /*TabHost.TabSpec 
	        spec=tabs.newTabSpec("mitab1");
	        spec.setContent(R.id.tab1);
	        spec.setIndicator("Médicos", res.getDrawable(R.drawable.iconome));        
	        tabs.addTab(spec);
	        
	        spec=tabs.newTabSpec("mitab2");
	        spec.setContent(R.id.tab2);
	        spec.setIndicator("Centros de Salud", res.getDrawable(R.drawable.iconocs));
	        tabs.addTab(spec);
	        
	        spec=tabs.newTabSpec("mitab3");
	        spec.setContent(R.id.tab3);
	        spec.setIndicator("Farmacias", res.getDrawable(R.drawable.iconofa));
	        tabs.addTab(spec);*/
	        TabHost.TabSpec 
	        spec=tabs.newTabSpec("mitab1");
	        spec.setContent(R.id.tab1);
	        spec.setIndicator("", res.getDrawable(R.drawable.iconome));        
	        tabs.addTab(spec);
	        
	        spec=tabs.newTabSpec("mitab2");
	        spec.setContent(R.id.tab2);
	        spec.setIndicator("", res.getDrawable(R.drawable.iconocs));
	        tabs.addTab(spec);
	        
	        spec=tabs.newTabSpec("mitab3");
	        spec.setContent(R.id.tab3);
	        spec.setIndicator("", res.getDrawable(R.drawable.iconofa));
	        tabs.addTab(spec);
	        
	        tabs.setCurrentTab(0);
	        
	        tabs.setOnTabChangedListener(new OnTabChangeListener() {
				//@Override
				public void onTabChanged(String tabId) {
					Log.i("AndroidTabsDemo", "Pulsada pesta�a: " + tabId);
				}
			});
	 
	 
			ListView l = (ListView) findViewById(R.id.listView1);
				 
			l.setAdapter(new miAdapter(this));		
			
			// seleccion menos 1
			//l.setSelection(1);
			
			l.setOnItemClickListener(new OnItemClickListener() {				                	
				
	            //@Override
	            public void onItemClick(AdapterView<?> parent, View v, int posicion, long id) {  
	            	
	            	/*ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
	                vf.setAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.push_left_in));           	               
	                vf.setDisplayedChild(posicion);*/
	            	
	            	switch (posicion){
                	case 0:
                		Intent intentfic = new Intent(frmpostvisitas.this, frmficheros.class);
                		startActivity(intentfic); 
                		break;
                	case 1:
                		Intent intentprev = new Intent(frmpostvisitas.this, frmprevisitas.class);
                		startActivity(intentprev); 
                		break;
                	case 2:
//                		Intent intentpost = new Intent(frmpostvisitas.this, frmpostvisitas.class);
//                		startActivity(intentpost); 
                		break;
                	case 3:
                		Intent intentnotif = new Intent(frmpostvisitas.this, frmnotificaciones.class);
                		startActivity(intentnotif); 
                		break;  
                	case 4:
                		Intent intentrep = new Intent(frmpostvisitas.this, frmreportes.class);
                		startActivity(intentrep); 
                		break;  
                	case 5:
                		Intent intentaus = new Intent(frmpostvisitas.this, frmausencias.class);
                		startActivity(intentaus); 
                		break;  
                	case 6:
                		Intent intentsinc = new Intent(frmpostvisitas.this, frmsincronizar.class);
                		startActivity(intentsinc); 
                		break;  
                	case 7:
                		Intent intentconf = new Intent(frmpostvisitas.this, frmconfiguracion.class);
                		startActivity(intentconf); 
                		break;  
                	case 8:
                		Intent intentlogin = new Intent(frmpostvisitas.this, LoginActivity.class);
                		   startActivity(intentlogin); 
                	       finishFromChild(getParent());
                	       moveTaskToBack(true);
                		break; 
	            	}	
	               
	            }
	        });
			                                                     
	    }
	 

		private static class miAdapter extends BaseAdapter {
	 
			private LayoutInflater mInflater;
	 
			private static final String[][] data = {{"Ficheros","1"}, {"PreVisitas","2"}, {"PostVisitas","3"}, {"Notificaciones","4"}, {"Reportes","5"}, {"Ausencias","6"}, {"Sincronizar","7"}, {"Configuracion","8"}, {"Salir","9"}};
			
			private static final int[][] dataimg =  {{R.drawable.icono,1},{R.drawable.icono1,2},{R.drawable.icono2,3},{R.drawable.icono3,4},{R.drawable.icono4,5},{R.drawable.icono5,6},{R.drawable.icono6,7},{R.drawable.icono7,8},{R.drawable.icono8,9}};
	 
			public miAdapter(Context context) {
	 
				mInflater = LayoutInflater.from(context);						
		    
			}
			
			
			public View getView(int position, View convertView, ViewGroup parent) {
	 
	 
				TextView text;
	 
				ImageView img1;
	 
	 
				if (convertView == null) {
	 
					convertView = mInflater.inflate(R.layout.listview_fila, null);				
	 
				} 
	 
				text = (TextView) convertView.findViewById(R.id.TextView01);
	  
				img1 = (ImageView) convertView.findViewById(R.id.ImageView01);
	 
				text.setText(data[position][0]);
	 
				img1.setImageResource(dataimg[position][0]);

				if (data[position][0] == "PostVisitas") {
					convertView.setSelected(true);
					convertView.setBackgroundResource(R.drawable.degrade_botonmenu);
				} else {
					convertView.setSelected(true);
					convertView.setBackgroundResource(R.drawable.degrade_transparent);
				}
	 
				return convertView;
	 
			}
	 
	 
			public int getCount() {
	 
				return data.length;
	 
			}
	 
	 
			public Object getItem(int position) {
	 
				return position;
				
	 
			}
	 
	 
			public long getItemId(int position) {
	 
				return position;
	 
			}		    
					
		}
			

}
